/*************************************************************************
	> File Name: 020.有效的括号_v1.c
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 五  9/ 3 16:07:45 2021
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

struct Stack {
    char *data;
    int top;
    int maxSize;
};

void initStack(struct Stack *s, int maxSize) {
    s->data = malloc(maxSize);
    s->top = 0;
}

bool isEmpty(struct Stack *s) {
    return s->top == 0;
}

void push(struct Stack *s, char c) {
    s->data[s->top++] = c;
}

void pop(struct Stack *s) {
    s->top--;
}

char top(struct Stack *s) {
    return s->data[s->top - 1];
}

bool isValid(char *s) {
    struct Stack stack;
    int len = strlen(s);
    initStack(&stack, len);
    for (int i = 0; s[i]; i++) {
        switch (s[i]) {
            case '(':
            case '[':
            case '{':
                push(&stack, s[i]);
                break;
            case ')':
                if (isEmpty(&stack)) return false;
                if (top(&stack) != '(') return false;
                pop(&stack);
                break;
            case '}':
                if (isEmpty(&stack)) return false;
                if (top(&stack) != '{') return false;
                pop(&stack);
                break;
            case ']':
                if (isEmpty(&stack)) return false;
                if (top(&stack) != '[') return false;
                pop(&stack);
                break;
            default:
                break;
        }
    }
    return isEmpty(&stack); 
}


int main() {
    char s[100] = {0};
    while (~scanf("%s", s)) {
        printf("isEmpty(stack) = %d\n", isValid(s));
    }
    return 0;
}

